<?php

define('IN_SEXMALL', true);

require(dirname(__FILE__) . '/includes/init.php');

/*------------------------------------------------------ */
//-- 框架
/*------------------------------------------------------ */
if ($_REQUEST['act'] == '')
{
	$smarty->assign('shop_url', urlencode(get_url()));
	$smarty->display('index.htm');
}

/*------------------------------------------------------ */
//-- 顶部框架的内容
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'top')
{
	// 获得管理员设置的菜单
	$lst = array();
	$admin_id = $mem->getCache('admin_id');
	$nav = $db->GetOne('SELECT nav_list FROM ' . TABLEPRE . "admin_user WHERE user_id = '" . $admin_id . "'");

	if (!empty($nav))
	{
		$arr = explode(',', $nav);

		foreach ($arr AS $val)
		{
			$tmp = explode('|', $val);
			$lst[$tmp[1]] = $tmp[0];
		}
	}

	// 获得管理员设置的菜单

	// 获得管理员ID
	$smarty->assign('send_mail_on',$_CFG['send_mail_on']);
	$smarty->assign('nav_list', $lst);
	$smarty->assign('admin_id', $admin_id);
	$smarty->assign('certi', $_CFG['certi']);

	$smarty->display('top.htm');
}

/*------------------------------------------------------ */
//-- 计算器
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'calculator')
{
	$smarty->display('calculator.htm');
}

/*------------------------------------------------------ */
//-- 左边的框架
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'menu')
{
	include_once('includes/inc_menu.php');

	// 权限对照表
	include_once('includes/inc_priv.php');

	foreach ($modules AS $key => $value)
	{
		ksort($modules[$key]);
	}
	ksort($modules);

	foreach ($modules AS $key => $val)
	{
		$menus[$key]['label'] = $_LANG[$key];
		if (is_array($val))
		{
			foreach ($val AS $k => $v)
			{
				if ( isset($purview[$k]))
				{
					if (is_array($purview[$k]))
					{
						$boole = false;
						foreach ($purview[$k] as $action)
						{
							$boole = $boole || admin_priv($action, '', false);
						}
						if (!$boole)
						{
							continue;
						}

					}
					else
					{
						if (! admin_priv($purview[$k], '', false))
						{
							continue;
						}
					}
				}
				if ($k == 'ucenter_setup' && $_CFG['integrate_code'] != 'ucenter')
				{
					continue;
				}
				$menus[$key]['children'][$k]['label']  = $_LANG[$k];
				$menus[$key]['children'][$k]['action'] = $v;
			}
		}
		else
		{
			$menus[$key]['action'] = $val;
		}

		// 如果children的子元素长度为0则删除该组
		if(empty($menus[$key]['children']))
		{
			//unset($menus[$key]);
		}

	}

	$smarty->assign('menus',     $menus);
	$smarty->assign('no_help',   $_LANG['no_help']);
	$smarty->assign('help_lang', $_CFG['lang']);
	$smarty->assign('charset', CHARSET);
	$smarty->assign('admin_id', $admin_id);
	$smarty->display('menu.htm');
}


/*------------------------------------------------------ */
//-- 清除缓存
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'clear_cache')
{
	clear_all_files();

	sys_msg($_LANG['caches_cleared']);
}


/*------------------------------------------------------ */
//-- 主窗口，起始页
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'main')
{

	$gd = gd_version();

	/* 检查文件目录属性 */
	$warning = array();

	if ($_CFG['shop_closed'])
	{
		$warning[] = $_LANG['shop_closed_tips'];
	}

	$open_basedir = ini_get('open_basedir');
	if (!empty($open_basedir))
	{
		/* 如果 open_basedir 不为空，则检查是否包含了 upload_tmp_dir  */
		$open_basedir = str_replace(array("\\", "\\\\"), array("/", "/"), $open_basedir);
		$upload_tmp_dir = ini_get('upload_tmp_dir');

		if (empty($upload_tmp_dir))
		{
			if (stristr(PHP_OS, 'win'))
			{
				$upload_tmp_dir = getenv('TEMP') ? getenv('TEMP') : getenv('TMP');
				$upload_tmp_dir = str_replace(array("\\", "\\\\"), array("/", "/"), $upload_tmp_dir);
			}
			else
			{
				$upload_tmp_dir = getenv('TMPDIR') === false ? '/tmp' : getenv('TMPDIR');
			}
		}

		if (!stristr($open_basedir, $upload_tmp_dir))
		{
			$warning[] = sprintf($_LANG['temp_dir_cannt_read'], $upload_tmp_dir);
		}
	}


	$result = file_mode_info('../' . DATA_DIR);
	if ($result < 2)
	{
		$warning[] = sprintf($_LANG['not_writable'], 'data', $_LANG['data_cannt_write']);
	}
	else
	{
		$result = file_mode_info('../' . DATA_DIR . '/afficheimg');
		if ($result < 2)
		{
			$warning[] = sprintf($_LANG['not_writable'], DATA_DIR . '/afficheimg', $_LANG['afficheimg_cannt_write']);
		}


		$result = file_mode_info('../' . DATA_DIR . '/feedbackimg');
		if ($result < 2)
		{
			$warning[] = sprintf($_LANG['not_writable'], DATA_DIR . '/feedbackimg', $_LANG['feedbackimg_cannt_write']);
		}

		$result = file_mode_info('../' . DATA_DIR . '/packimg');
		if ($result < 2)
		{
			$warning[] = sprintf($_LANG['not_writable'], DATA_DIR . '/packimg', $_LANG['packimg_cannt_write']);
		}
	}

	$result = file_mode_info('../images');
	if ($result < 2)
	{
		$warning[] = sprintf($_LANG['not_writable'], 'images', $_LANG['images_cannt_write']);
	}
	else
	{
		$result = file_mode_info('../' . IMAGE_DIR . '/upload');
		if ($result < 2)
		{
			$warning[] = sprintf($_LANG['not_writable'], IMAGE_DIR . '/upload', $_LANG['imagesupload_cannt_write']);
		}
	}

	$result = file_mode_info('../temp');
	if ($result < 2)
	{
		$warning[] = sprintf($_LANG['not_writable'], 'images', $_LANG['tpl_cannt_write']);
	}

	$result = file_mode_info('../temp/backup');
	if ($result < 2)
	{
		$warning[] = sprintf($_LANG['not_writable'], 'images', $_LANG['tpl_backup_cannt_write']);
	}

	clearstatcache();

	$smarty->assign('warning_arr', $warning);


	$smarty->assign('admin_msg', $admin_msg);

	$mysql_ver = $db->version();   // 获得 MySQL 版本

	/* 系统信息 */
	$sys_info['os']            = PHP_OS;
	$sys_info['ip']            = $_SERVER['SERVER_ADDR'];
	$sys_info['web_server']    = $_SERVER['SERVER_SOFTWARE'];
	$sys_info['php_ver']       = PHP_VERSION;
	$sys_info['mysql_ver']     = $mysql_ver;
	$sys_info['zlib']          = function_exists('gzclose') ? $_LANG['yes']:$_LANG['no'];
	$sys_info['safe_mode']     = (boolean) ini_get('safe_mode') ?  $_LANG['yes']:$_LANG['no'];
	$sys_info['safe_mode_gid'] = (boolean) ini_get('safe_mode_gid') ? $_LANG['yes'] : $_LANG['no'];
	$sys_info['timezone']      = function_exists("date_default_timezone_get") ? date_default_timezone_get() : $_LANG['no_timezone'];
	$sys_info['socket']        = function_exists('fsockopen') ? $_LANG['yes'] : $_LANG['no'];

	if ($gd == 0)
	{
		$sys_info['gd'] = 'N/A';
	}
	else
	{
		if ($gd == 1)
		{
			$sys_info['gd'] = 'GD1';
		}
		else
		{
			$sys_info['gd'] = 'GD2';
		}

		$sys_info['gd'] .= ' (';

		/* 检查系统支持的图片类型 */
		if ($gd && (imagetypes() & IMG_JPG) > 0)
		{
			$sys_info['gd'] .= ' JPEG';
		}

		if ($gd && (imagetypes() & IMG_GIF) > 0)
		{
			$sys_info['gd'] .= ' GIF';
		}

		if ($gd && (imagetypes() & IMG_PNG) > 0)
		{
			$sys_info['gd'] .= ' PNG';
		}

		$sys_info['gd'] .= ')';
	}


	/* 允许上传的最大文件大小 */
	$sys_info['max_filesize'] = ini_get('upload_max_filesize');

	$smarty->assign('sys_info', $sys_info);


	$smarty->assign('ecs_version',  VERSION);
	$smarty->assign('ecs_release',  RELEASE);
	$smarty->assign('ecs_lang',     $_CFG['lang']);
	$smarty->assign('ecs_charset',  strtoupper(CHARSET));

	$smarty->display('start.htm');
}


/*------------------------------------------------------ */
//-- 拖动的帧
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'drag')
{
	$smarty->display('drag.htm');;
}

?>